package com.xiao.community.service.impl;

import com.xiao.community.feign.UserFeign;
import com.xiao.group.common.Vo.UsersEntity;
import com.xiao.group.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiao.group.common.utils.PageUtils;
import com.xiao.group.common.utils.Query;

import com.xiao.community.dao.OrderDao;
import com.xiao.community.entity.OrderEntity;
import com.xiao.community.service.OrderService;


@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<OrderEntity> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("order_status");
        IPage<OrderEntity> page = this.page(
                new Query<OrderEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

    @Autowired
    OrderService orderService;

    @Autowired
    UserFeign userFeign;
    @Override
    public OrderEntity findorderid(String out_trade_no) {
        OrderEntity byId = orderService.getById(Integer.parseInt(out_trade_no));
        //支付成功后的回调
        byId.setOrderStatus(1);
        byId.setPayDate(new Date());
        boolean b = orderService.updateById(byId);
        if(b){
            return byId;
        }
        return null;
    }

    @Override
    public R touserList(Integer userId) {
//        UsersEntity usersEntity = userFeign.info(userId);
        List<OrderEntity> orderEntities = baseMapper.selectList(new QueryWrapper<OrderEntity>().eq("admin_id", userId));
        return R.ok().put("data",orderEntities);
    }

}